package com.ycfmedical.bed.ui.fragment;

import com.ycfmedical.bed.ApiConfigs;
import com.ycfmedical.bed.Constants;
import com.ycfmedical.bed.adapter.HealthFoodAdapter;
import com.ycfmedical.bed.base.BaseHealthFragment;
import com.ycfmedical.bed.model.HealthResults;
import com.ycfmedical.bed.ui.HealthDetailActivity;

import android.os.Bundle;

import cn.droidlover.xdroidmvp.base.SimpleRecAdapter;
import cn.droidlover.xrecyclerview.RecyclerItemCallback;
import cn.droidlover.xrecyclerview.XRecyclerView;

/**
 * 健康饮食 fragment Created by wanglei on 2016/12/31.
 */
public class HealthFoodFragment extends BaseHealthFragment
{

    HealthFoodAdapter adapter;

    @Override
    public SimpleRecAdapter getAdapter()
    {
        if (adapter == null)
        {
            adapter = new HealthFoodAdapter(context);

            // 设置点击事件，点击Item
            adapter.setRecItemClick(
                new RecyclerItemCallback<HealthResults.ResultBean, HealthFoodAdapter.ViewHolder>()
                {
                    @Override
                    public void onItemClick(int position, HealthResults.ResultBean model, int tag,
                                            HealthFoodAdapter.ViewHolder holder)
                    {
                        super.onItemClick(position, model, tag, holder);
                        switch (tag)
                        {
                            case HealthFoodAdapter.TAG_VIEW:
                                Bundle mBundle = new Bundle();
                                mBundle.putParcelable(Constants.HEALTHNEWS,model);
                                HealthDetailActivity.launch(context,mBundle);
                                break;
                        }
                    }
                });
        }
        return adapter;
    }

    @Override
    public void setLayoutManager(XRecyclerView recyclerView)
    {
        recyclerView.verticalLayoutManager(context);
    }

    // 获得Fragemnt的种类
    @Override
    public int getType()
    {
        return ApiConfigs.HEALTH_FOOD;
    }

    public static HealthFoodFragment newInstance()
    {
        return new HealthFoodFragment();
    }
}
